Public Class Mutex
    Dim Locked As Boolean
    Dim timeout As Integer
    Public Sub New(Optional ByVal timeout As Integer = ThreadSleepTime)
        Me.timeout = timeout
        Locked = False
    End Sub
    Public Sub Lock()
        While Locked
            Threading.Thread.Sleep(timeout)
        End While
        Locked = True
    End Sub
    Public Sub Unlock()
        Locked = False
    End Sub
End Class